<article class="cl pd-20">
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <!-- <a href="javascript:;" onclick="del_all()" class="btn btn-danger radius">
                <i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> -->
            <a class="btn btn-primary radius" href="javascript:save(0);">
                <i class="Hui-iconfont">&#xe600;</i> 添加栏目</a>
        </span>
    </div>
    <div class="mt-10" style="min-width:920px;">
        <table class="table table-border table-bordered table-hover table-bg">
            <thead>
                <tr class="text-c">
                    <th width="60px">ID</th>
                    <th>栏目名称</th>
                    <!-- <th>url</th> -->
                    <th>模块名</th>
                    <th>导航状态</th>
                    <th style="width: 100px;">排序</th>
                    <th>类型</th>
                    <th>添加时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {foreach $list as $value}
                <tr class="text-c">
                    <td>{$value.id}</td>
                    <td class="text-l">{notempty name="value.child"}
                        <a href="javascript:void(0);" title="展开" data-status="1"
                            onClick="loadchild(this,'{$value.id}')">
                            <i class="Hui-iconfont">&#xe6d7;</i></a>{/notempty}
                        {$value.name}</td>
                    <!-- <td>{//$value.url}</td> -->
                    <td>{$value.module}</td>
                    <td class="td-status-nav">
                        <div class="switch size-S" data-on-label="是" data-off-label="否" data-id="{$value.id}">
                            <input type="checkbox" {if $value.is_nav==1}checked{/if}>
                        </div>
                    </td>
                    <td><input type="text" class="input-text input-sort" value="{$value.sort}" data-id="{$value.id}"
                        style="text-align: center;"></td>
                    <td>{$types[$value['type']]}</td>
                    <td>{$value.create_time}</td>
                    <td class="td-manage">
                        <a  title="编辑" href="javascript:save({$value.id});" class="btn btn-primary radius">
                            <i class="Hui-iconfont">&#xe6df;</i></a>
                        <a title="删除" href="javascript:;" onclick="del(this,'{$value.id}')" class="ml-5 btn btn-danger radius">
                            <i class="Hui-iconfont">&#xe6e2;</i></a>
                    </td>
                </tr>
                {notempty name="value.child"} {foreach $value.child as $val}
                <tr class="text-c parent_{$value.id}">
                    <td>{$val.id}</td>
                    <td class="text-c">{notempty name="val.child"}
                        <a class="child ml-20" href="javascript:void(0);" title="展开" data-status="1"
                            onClick="loadchild(this,'{$val.id}')">
                            <i class="Hui-iconfont">&#xe6d7;</i>
                            {else/}
                            <a class="child ml-20" href="javascript:void(0);">
                                {/notempty}
                                {$val.name}</a>
                    </td>
                    <!-- <td>{//$val.url}</td> -->
                    <td>{$val.module}</td>
                    <td class="td-status-nav">
                        <div class="switch size-S" data-on-label="是" data-off-label="否" data-id="{$val.id}">
                            <input type="checkbox" {if $val.is_nav==1}checked{/if}>
                        </div>
                    </td>
                    <td><input type="text" class="input-text input-sort" value="{$val.sort}" data-id="{$val.id}"
                        style="text-align: center;"></td>
                    <td>{$types[$val['type']]}</td>
                    <td>{$val.create_time}</td>
                    <td class="td-manage">
                        <a  title="编辑" href="javascript:save({$val.id});" class="btn btn-primary radius">
                            <i class="Hui-iconfont">&#xe6df;</i></a>
                        <a title="删除" href="javascript:;" onclick="del(this,'{$val.id}')" class="ml-5 btn btn-danger radius">
                            <i class="Hui-iconfont">&#xe6e2;</i></a>
                    </td>
                </tr>
                {notempty name="val.child"} {foreach $val.child as $vo}
                <tr class="text-c grandparent_{$value.id} parent_{$val.id}">
                    <td>{$vo.id}</td>
                    <td class="text-r">{$vo.name}</td>
                    <!-- <td>{//$vo.url}</td> -->
                    <td>{$vo.module}</td>
                    <td class="td-status-nav">
                        <div class="switch size-S" data-on-label="是" data-off-label="否" data-id="{$vo.id}">
                            <input type="checkbox" {if $vo.is_nav==1}checked{/if}>
                        </div>
                    </td>
                    <td><input type="text" class="input-text input-sort" value="{$vo.sort}" data-id="{$val.id}"
                        style="text-align: center;"></td>
                    <td>{$types[$vo['type']]}</td>
                    <td>{$vo.create_time}</td>
                    <td class="td-manage">
                        <a  title="编辑" href="javascript:save({$vo.id});" class="btn btn-primary radius">
                            <i class="Hui-iconfont">&#xe6df;</i></a>
                        <a title="删除" href="javascript:;" onclick="del(this,'{$vo.id}')" class="ml-5 btn btn-danger radius">
                            <i class="Hui-iconfont">&#xe6e2;</i></a>
                    </td>
                </tr>
                {/foreach} {/notempty}{/foreach} {/notempty} {/foreach}
            </tbody>
        </table>
    </div>
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    function save(id) {
        var title = id == 0 ? '添加栏目' : '修改栏目'
        var url = "{:url('/sys/category/save')}" + "?_layer=true&id=" + id
        layer_show(title, url, 900);
    }

    // 改变状态
    $('.td-status-nav .switch').on('switch-change', function () {
        var id = $(this).data('id');

        var data = {
            'id': parseInt(id)
        };

        $.post('navStatus', data, function (res) {
            if (res.code == 0) {
                topalert({
                    type: 0,
                    content: res.msg,
                    speed: 1000
                });
            } else {
                topalert({
                    type: 1,
                    content: res.msg,
                    speed: 1000
                });
                return false;
            }
        }, 'json');
    });

    function loadchild(obj, id) {
        var status = $(obj).data('status');
        // console.log(obj);
        // console.log(id);
        // console.log(status);

        if (status == 1) {
            $(".parent_" + id).css("display", "none");
            $(".parent_" + id).find("td a.child").children('i').html('&#xe6d7;');
            $(".parent_" + id).find("td a.child").data('status', 0);
            $(".grandparent_" + id).css("display", "none");
            $(obj).children('i').html('&#xe6d7;');
            $(obj).data('status', 0);
            return false;
        }
        $(".parent_" + id).css('display', '');
        $(obj).children('i').html('&#xe6d5;');
        $(obj).data('status', 1);
    }
</script>
<!--请在上方写此页面业务相关的脚本-->